Shader "Custom/Specular_Gouroude" {
	Properties {
		_Color("color",color) = (1,1,1,1)
		_SpecularColor("specular",color) = (1,0,0,0)
		_SpecularPower("SpcularPower",float) = 128
	}
	SubShader {
		Tags { "RenderType"="Opaque" "LightMode"="ForwardBase"}
		LOD 200
		Pass{
		CGPROGRAM
		#include "UnityCG.cginc"
		#pragma vertex vert
		#pragma fragment frag
		
		float4 _Color;
		float4 _LightColor0;
		float4 _SpecularColor;
		float _SpecularPower;
		
		struct v2f{
			float4 pos:POSITION;
			float4 color:TEXCOORD;
		};
		
		v2f vert(appdata_base i){
			v2f v;
			v.pos = mul(UNITY_MATRIX_MVP,i.vertex);
			
			float4 worldPos = mul(_Object2World,i.vertex);
			
			float3 normal = normalize(mul(float4(i.normal,0),_World2Object).xyz);
			float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
			
			float diff = max(0,dot(normal,lightDir));
			v.color = _Color * _LightColor0 * diff;
			
			float3 viewDir = normalize(_WorldSpaceCameraPos.xyz - worldPos.xyz);
			float3 refDir = reflect(-_WorldSpaceLightPos0.xyz,normal);
			float spec = pow(max(0,dot(viewDir,refDir)),_SpecularPower);
			v.color += _SpecularColor * spec;
			
			return v;
		}
		
		float4 frag(v2f i):COLOR{
			return i.color;
		}
		
		ENDCG
		}
	} 
	FallBack "Diffuse"
}
